/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package com.gitee.minimalismstyle.fresh.sys.api.service

import com.alicp.jetcache.anno.Cached
import com.gitee.minimalismstyle.fresh.common.api.annotation.ControllerFeignClient
import com.gitee.minimalismstyle.fresh.common.core.const.CacheConst
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.common.core.domain.Resource
import com.gitee.minimalismstyle.fresh.common.data.commons.service.LongModelBaseService
import com.gitee.minimalismstyle.fresh.sys.api.model.SysResource
import com.gitee.minimalismstyle.fresh.sys.api.config.SysApiConst
import io.swagger.annotations.Api
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable

/**
 * 资源业务接口
 * @author maochao
*/
@Api(value = "sysResource", tags = ["资源业务接口"])
@ControllerFeignClient(serviceId = SysApiConst.SERVICE_ID, ctx =SysApiConst.CTX, path = "/sysResource")
interface SysResourceService: LongModelBaseService<SysResource> {

    @GetMapping("getResourceByServiceId/{serviceId}")
    fun getResourceByServiceId(@PathVariable serviceId : String) : R<List<Resource>>

    /**
     * 根据资源类型查询资源列表
     * @param type
     * @return
     */
    @Cached(name="resourceCache-", key="#type", expire = CacheConst.CACHE_DEFAULT_EXPIRE)
    @GetMapping("findByType")
    fun findByType(type: String): R<List<SysResource>>

    /**
     * 获取根资源
     * @return
     */
    @GetMapping("findRootResources")
    fun findRootResources(): R<List<SysResource>>

    @GetMapping("findByParentId/{parentId}")
    fun findByParentId(@PathVariable parentId: String): R<List<SysResource>>

    /**
     * 重置资源权限
     * @return
     */
    @GetMapping("reload")
    fun reload(): R<Boolean>
}